public class FirstThread extends Thread{
    private String name;
    public FirstThread(String name){
        super(name);
        System.out.println(name+"创建成功");
    }
    public void run(){
        for(int i=0;i<10;i++){
            try{
                Thread.sleep(1000);
            }catch(Exception e){}
            System.out.println(Thread.currentThread().getName()+i+"次运行");
            Thread.yield();//让当前线程让出CPU
        }
    }
    public static void main(String[] args){
        FirstThread t1=new FirstThread("第一个线程");
        FirstThread t2=new FirstThread("第二个线程");
        FirstThread t3=new FirstThread("第三个线程");
        FirstThread t4=new FirstThread("第四个线程");
        FirstThread t5=new FirstThread("第五个线程");
        FirstThread t6=new FirstThread("第六个线程");
        FirstThread t7=new FirstThread("第七个线程");
        System.out.println("开始启动");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
        t7.start();
        System.out.println("main方法运行完毕");
    }
}
